package com.avoid.easymqtt.mqtt.protocol;

import io.netty.handler.codec.mqtt.MqttConnAckMessage;
import io.netty.handler.codec.mqtt.MqttConnAckVariableHeader;
import io.netty.handler.codec.mqtt.MqttConnectReturnCode;
import io.netty.handler.codec.mqtt.MqttFixedHeader;
import io.netty.handler.codec.mqtt.MqttMessageType;
import io.netty.handler.codec.mqtt.MqttProperties;
import io.netty.handler.codec.mqtt.MqttQoS;

/**
 * 描述
 *
 * @author avoid@fiture.com
 * @date 2022/5/7
 * @motto Life is so short,do something to make yourself happy,such as coding
 */
public class MqttMessageFactory {

    public static MqttConnAckMessage getConnectAckMessage(MqttConnectReturnCode returnCode, boolean sessionPresent,
        MqttProperties properties) {
        MqttFixedHeader fixedHeader =
            new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
        MqttConnAckVariableHeader variableHeade;
        if (null == properties) {
            variableHeade = new MqttConnAckVariableHeader(returnCode, sessionPresent);
        } else {
            variableHeade = new MqttConnAckVariableHeader(returnCode, sessionPresent, properties);
        }
        return new MqttConnAckMessage(fixedHeader, variableHeade);
    }

}
